import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true,
  },
]

export const asyncRoutes = [{
  path: '/',
  component: Layout,
  redirect: '/dashboard',
  children: [{
    path: 'dashboard',
    name: 'Dashboard',
    component: () => import('@/views/manager/dashboard/index'),
    meta: { title: '项目基本信息', icon: 'dashboard' }
  }],
  meta: { requireAuth: true, roles: ['manager'] }
},

{
  path: '/staff',
  component: Layout,
  children: [{
    path: 'staff',
    name: 'Staff',
    component: () => import('@/views/manager/staff/index'),
    meta: { title: '人员管理', icon: 'example' }
  }],
  meta: { requireAuth: true, roles: ['manager'] }
  },

  {
    path: '/status',
    component: Layout,
    children: [{
      path: 'status',
      name: 'Status',
      component: () => import('@/views/manager/status/index'),
      meta: { title: '项目管理', icon: 'example' }
    }],
    meta: { requireAuth: true, roles: ['manager'] }
  },
  {
    path: '/statement',
    component: Layout,
    children: [{
      path: 'statement',
      name: 'Statement',
      component: () => import('@/views/manager/statement/index'),
      meta: { title: '报表管理', icon: 'example' }
    }],
    meta: { requireAuth: true, roles: ['manager'] }
  },

{
  path: '/',
  component: Layout,
  redirect: '/dashboard',
  children: [{
    path: 'dashboard',
    name: 'Dashboard',
    component: () => import('@/views/employee/dashboard/index'),
    meta: { title: '项目基本信息', icon: 'dashboard' }
  }],
  meta: { requireAuth: true, roles: ['employee'] }
},
{
  path: '/staff',
  component: Layout,
  children: [{
    path: 'staff',
    name: 'Staff',
    component: () => import('@/views/employee/staff/index'),
    meta: { title: '个人信息管理', icon: 'example' }
  }],
  meta: { requireAuth: true, roles: ['employee'] }
  },
  {
    path: '/status',
    component: Layout,
    children: [{
      path: 'status',
      name: 'Status',
      component: () => import('@/views/employee/status/index'),
      meta: { title: '项目状态', icon: 'example' }
    }],
    meta: { requireAuth: true, roles: ['employee'] }
  },
  {
    path: '/statement',
    component: Layout,
    children: [{
      path: 'statement',
      name: 'Statement',
      component: () => import('@/views/employee/statement/index'),
      meta: { title: '报表下载', icon: 'example' }
    }],
    meta: { requireAuth: true, roles: ['employee'] }
  },

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
